<?php form_pr('RequestProperties','_self','?action=requests','post');
	mn_field('hidden','ED','AddRequest','','','','',''); ?>
<table width="100%"  border="0" cellspacing="1" cellpadding="3">
<?php 
    $Activities = $GLOBALS['CONN']->db_array("SELECT 
					ccenter_requests.Ref,
					ccenter_requests.RefUser,
					ccenter_requests.Observations,
					hcce_status.name AS Status,
					ccenter_requests.TimeCreated,
					ccenter_requests.TimeDelivered,
					ccenter_requests.TimeReceived,
					ccenter_requests.TimeAproval,
					ccenter_requests.RefAproval AS Aproval,
					ccenter_requests.RefSupervisor,
					main_offices.name AS Office,
					main_users.name AS User
				FROM ccenter_requests
				INNER JOIN main_offices ON main_offices.ref = ccenter_requests.RefOffice
				INNER JOIN main_users ON main_users.ref = ccenter_requests.RefUser
				INNER JOIN hcce_status ON hcce_status.ref = ccenter_requests.Status
				WHERE ccenter_requests.RefUser = {$_SESSION['UtID']} AND Status = 0
				ORDER BY ccenter_requests.TimeCreated DESC, ccenter_requests.Ref DESC LIMIT 0,1"); 
				
	if (!isset($Activities[1])) {
	
	 $GLOBALS['CONN']->db_query("INSERT INTO ccenter_requests
				(RefUser, RefOffice, RefDomain, Observations, Status)
				VALUES 
				({$_SESSION['UtID']},{$_SESSION['office']},1,'',0)"); 
	
    $Activities = $GLOBALS['CONN']->db_array("SELECT 
					ccenter_requests.Ref,
					ccenter_requests.RefUser,
					ccenter_requests.Observations,
					hcce_status.name AS Status,
					ccenter_requests.TimeCreated,
					ccenter_requests.TimeDelivered,
					ccenter_requests.TimeReceived,
					ccenter_requests.TimeAproval,
					ccenter_requests.RefAproval AS Aproval,
					ccenter_requests.RefSupervisor,
					main_offices.name AS Office,
					main_users.name AS User
				FROM ccenter_requests
				INNER JOIN main_offices ON main_offices.ref = ccenter_requests.RefOffice
				INNER JOIN main_users ON main_users.ref = ccenter_requests.RefUser
				INNER JOIN hcce_status ON hcce_status.ref = ccenter_requests.Status
				WHERE ccenter_requests.RefUser = {$_SESSION['UtID']} AND Status = 0
				ORDER BY ccenter_requests.TimeCreated DESC, ccenter_requests.Ref DESC LIMIT 0,1"); 
	}
	
	for ($f = 1; $f <= $Activities[0]; $f++) { ?>

  <tr>
    <td width="25%" rowspan="4" bgcolor="#ACB1CC"><div align="right">
	<img src="<?php echo $GLOBALS['GFX'];?>CentrodeCustos/requests.png"></div></td>
    <td bgcolor="#ACB1CC"><input name="Ref" type=text value="<?php echo $Activities[1]['Ref'];?>" size="6" readonly="">
    </td>
  </tr>
  <tr>
    <td bgcolor="#ACB1CC">Cliente:
      <?php echo $Activities[1]['Office'];?>      </td>
  </tr>
  <tr>
    <td bgcolor="#ACB1CC">Data:
      <?php echo $Activities[1]['TimeCreated'];?></td>
  </tr>
  <tr>
    <td bgcolor="#ACB1CC">Por:
    <?php echo $Activities[1]['User'];?></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td valign="top"><div align="right">ObservaÇ&otilde;es</div></td>
    <td width="75%"><textarea name="Observations" cols="60" rows="4"><?php echo $Activities[1]['Observations'];?></textarea></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td colspan="2">
 <?php include($GLOBALS['PAD'].'Modules/CentrodeCustos/Lib/list_requests_article.mex'); ?></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td>Estado: </td>
    <td><?php echo $Activities[1]['Status'];?></td>
  </tr>
  <?php if ($Activities[1]['TimeAproval'] =! null) { ?>
  <tr bgcolor="#F2F2F2">
    <td> Aprovação: </td>
    <td><?php if ($Activities[1]['Aproval'] > 0) { $Activities[1]['Aproval'].', a '.$Activities[1]['TimeAproval']; } 
	else { echo 'A aguardar aprova��o'; }?></td>
  </tr>
  <?php } 
  		if ($Activities[1]['TimeDelivered'] != null) { ?>
  <tr bgcolor="#F2F2F2">
    <td>Data Para Entrega </td>
    <td><?php echo $Activities[1]['TimeAproval'];?></td>
  </tr>
  <?php }
  if ($Activities[1]['TimeDelivered'] != null && $Activities[1]['TimeReceived'] == null) { ?>
  <tr bgcolor="#F2F2F2">
    <td valign="top">Confirmar Entrega:</td>
    <td><?php mn_field('date','ED','DateReceived','','','','',''); ?><input name="DateReceived" type="text" id="DateReceived" onFocus="this.select();lcs(this)" 
	  onClick="event.cancelBubble=true;this.select();lcs(this)" 
	  value="<?php echo $_POST['TimeReceived'];?>" size="8" maxlength="10" /></td>
  </tr>
  <?php } else { ?>
  <tr bgcolor="#F2F2F2">
    <td valign="top">Data de Entrega:</td>
    <td><?php echo $Activities[1]['TimeReceived'];?></td>
  </tr>
  <?php } ?>
  <tr bgcolor="#F2F2F2">
    <td>&nbsp;</td>
    <td><input type="submit" name="UpdateRequest" value="Submeter"></td>
  </tr>
  <?php } ?>
</table>
</form>